import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
import {GnTreeComponent} from "geminis-ng";

@Component({
  selector: 'gn-resources-organization-tree',
  templateUrl: './organization-tree.component.html'
})
export class OrganizationTreeComponent {

  @ViewChild(GnTreeComponent, {static: true})
  public tree: GnTreeComponent;

  @Output() onSelectionChanged = new EventEmitter();

  get selectedData(): any {
    if (this.tree && this.tree.selected) {
      return this.tree.selected.data;
    }
    this.tree.rootData.pathId = '/';
    return this.tree.rootData;
  }

  selectionChanged() {
    this.onSelectionChanged.emit();
  }

}

